package com.vichat.common.rudp;


import java.net.SocketAddress;


public class RudpBlockData {
    public int msgType = 0; //0, req, 1, ack
    public int blockId;
    public byte[] transId;
    public SocketAddress desAddress;


    public int lifeTime = 5;//in second
    public int interTime = 500;//mil sec
    public long firstTime = 0;
    public long lastTime = 0;
    public int blockNum;
    public int blockLen;
    public byte[] blockData;

    public int resendNums = 0;
    public byte[] pocketArray = null;
    public String blockKey = null;
    private String strTransId = null;

    public RudpBlockData() {

    }

    public RudpBlockData(RudpBlockData blockData) {
        msgType = 1;
        blockId = blockData.blockId;
        transId = blockData.transId;

    }

    public RudpBlockData(int inblockId, byte[] intransId, int inlifeTime, int inblockNum, int inblockLen, byte[] inblockData) {
        msgType = 0;
        blockId = inblockId;
        transId = intransId;
        lifeTime = inlifeTime;
        blockNum = inblockNum;
        blockLen = inblockLen;
        blockData = inblockData;
    }

    public String getBlockKey() {
        if (blockKey == null) {
            StringBuilder keybd = new StringBuilder();
            for (int tt = 0; tt < transId.length; tt++) {
                keybd.append(transId[tt]).append("-");
            }
            keybd.append(blockId);
            blockKey = keybd.toString();
        }
        return blockKey;
    }

    public byte[] toPocketArray() {
        if (pocketArray == null) {
            if (msgType == 0)
                pocketArray = RudpDataUtil.marshalBlockData(this);
            else
                pocketArray = RudpDataUtil.marshalAckData(this);
        }
        return pocketArray;
    }

    public String getStringTrans() {
        if (strTransId == null) {
            strTransId = ProtocolUtil.transIdStr(this.transId);
        }
        return strTransId;
    }
    
    
    


}
